package com.itheima.service.impl;
import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

//当存在多个相同类型的Bean注入时，加上@Primary注解，来确定默认的实现
@Primary
@Service   //命名
public class DeptServiceImpl implements DeptService {

//    //@Autowired默认按照类型注入
//    @Autowired
//    @Qualifier("deptDaoImpl")   //@Qualifier只能和@Autowired一起使用

    //默认按照名称注入
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> getDeptList(){
        List<Dept> deptList = deptMapper.queryDepts();
        return deptList;
    }

    @Override
    public void deleteDeptById(Integer id){
        deptMapper.deleteDept(id);
    }

    @Override
    public void saveDept(String name) {
        deptMapper.saveDept(name);
    }

    @Override
    public Dept getById(Integer id){
        return deptMapper.getById(id);
    }

    @Override
    public void updateDept(Dept dept){
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);
    }
}
